<template>
  <view class="content">
    <view class="fao-box">
      <view class="order-tba">
        <text :class="index == -1?'active':''" @click="fanlei('',-1)">全部问题</text>
        <text
          :class="index == i?'active':''"
          v-for="(item,i) in fenleiList"
          :key="i"
          @click="fanlei(item.id,i)"
        >{{item.name}}</text>
      </view>
      <view class="fao-list">
        <view
          class="my-list-a"
          v-for="(item,index) in list"
          :key="index"
          @click="xiangqing(item.id)"
        >
          <text>{{item.title}}</text>
        </view>
      </view>
    </view>
    <dacizinavtag :current="item_index" @click="tabClick"></dacizinavtag>
  </view>
</template>

<script>
import dacizinavtag from "@/components/dacizi-navtag/dacizi-navtag.vue";
export default {
  components: {
    dacizinavtag,
  },
  data() {
    return {
      item_index: 4, // 单页面id
      index: -1,
      fenleiList: [],
      list: [],
      page: 1,
      psize: 10
    };
  },
  onLoad() {
    this.getFenlei();
    this.getList("");
  },
  methods: {
    getFenlei() {
      var than = this;
      uni.request({
        url: getApp().globalData.http + "/page/cats",
        data: "",
        method: "post",
        header: {
          "content-type": "application/x-www-form-urlencoded",
          token: uni.getStorageSync("token")
        },
        success: res => {
          if (res.data.code == 1) {
            than.fenleiList = res.data.data;
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: "none",
              duration: 2000
            });
          }
        }
      });
    },
    getList(id) {
      var than = this;
      uni.request({
        url: getApp().globalData.http + "/page/getList",
        data: {
          cat_id: id,
          page: this.page,
          psize: this.psize
        },
        method: "post",
        header: {
          "content-type": "application/x-www-form-urlencoded",
          token: uni.getStorageSync("token")
        },
        success: res => {
          console.log(res.data.data);
          if (res.data.code == 1) {
            than.list = res.data.data.data;
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: "none",
              duration: 2000
            });
          }
        }
      });
    },
    xiangqing(id) {
      wx.navigateTo({
        url: '/pages/my/fao-info?id=' + id
      });
    },
    fanlei(id, num) {
      this.index = num;
      this.getList(id);
    }
  }
};
</script>
